package altanovela.mybatis.act;

import java.util.List;
import altanovela.mybatis.model.Mahasiswa;
import altanovela.mybatis.model.MahasiswaMapper;

public class MainApplication {
	private MahasiswaMapper mhsmap;
	private List<Mahasiswa> resultlist;
	private Mahasiswa result;
	
	public void beginProcess(){
		System.out.println("\n.: DATA MAHASISWA :.");
		showData();
		
		System.out.println("\ninserting data...");
		Mahasiswa newmhs = new Mahasiswa();
		newmhs.setID_MHS("IDMHS5");
		newmhs.setNAMA_MHS("Timun Mas");
		newmhs.setJK_MHS("P");
		newmhs.setJURUSAN("Sastra");
		mhsmap.insertData(newmhs);
		
		showData();
		
		result = mhsmap.showCrtData("IDMHS5");
		if(result!=null){
			System.out.println("\nCONDITION > ID = IDMHS5");
			System.out.println(result.getID_MHS()+" " +
					   		   result.getNAMA_MHS()+" " +
					   		   result.getJK_MHS()+" " +
					   		   result.getJURUSAN());
		}
	}

	public void showData(){
		resultlist = mhsmap.showAllData();
		if(resultlist!=null){
			System.out.println("CONDITION > ALL, ORD BY NAME ASC");
			for (Mahasiswa mhs : resultlist) {
				System.out.println(mhs.getID_MHS()+" " +
								   mhs.getNAMA_MHS()+" " +
								   mhs.getJK_MHS()+" " +
								   mhs.getJURUSAN());
			}
		}
	}
	// SETTER AND GETTER
	public MahasiswaMapper getMhsmap() {
		return mhsmap;
	}
	public void setMhsmap(MahasiswaMapper mhsmap) {
		this.mhsmap = mhsmap;
	}
}

